package com.sevenGroup.pawnshop.dao;

import com.sevenGroup.pawnshop.controller.form.AuthenticateForm;
import com.sevenGroup.pawnshop.model.Authenticate;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sevenGroup.pawnshop.model.AuthenticateSelectConditional;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author sevenGroup
 * @since 2022-02-16
 */
public interface AuthenticateDao extends BaseMapper<Authenticate> {
//  新增鉴定
    @Insert("insert into authenticate values (default,#{goodId},#{authenticateDegree},#{authenticateRemark},#{authenticateResult},#{authenticateUserId},#{authenticateUserName},#{authenticateTime})")
    Integer addAuthenticate(Authenticate authenticate);
//  查询鉴定集合
    @Select("<script> select * from authenticate where 1=1" +
            "<if test=\"goodId != null\"> and good_id=#{goodId} </if> " +
            "<if test=\"authenticateDegrees != null\"> and authenticate_degree in <foreach item='item1' collection='authenticateDegrees' open='(' separator=',' close=')'> #{item1} </foreach> </if> " +
            "<if test=\"authenticateResults != null\"> and authenticate_result in <foreach item='item2' collection='authenticateResults' open='(' separator=',' close=')'> #{item2} </foreach> </if> " +
            "<if test=\"authenticateUserId != null\"> and authenticate_user_id=#{authenticateUserId} </if> " +
            "<if test=\"authenticateBeginTimes != null\"> and authenticate_time between #{authenticateBeginTimes} and #{authenticateEndTimes} </if> " +
            "ORDER BY authenticate_time DESC </script>")
    @Results(id = "",value = {
            @Result(column = "authenticate_id",property = "authenticateId"),
            @Result(column = "good_id",property = "goodId"),
            @Result(column = "authenticate_degree",property = "authenticateDegree"),
            @Result(column = "authenticate_remark",property = "authenticateRemark"),
            @Result(column = "authenticate_result",property = "authenticateResult"),
            @Result(column = "authenticate_user_id",property = "authenticateUserId"),
            @Result(column = "authenticate_user_name",property = "authenticateUserName"),
            @Result(column = "authenticate_time",property = "authenticateTime"),

    })
    List<Authenticate> selectAuthenticate(AuthenticateSelectConditional conditional);
}
